package com.easybacklog.client.sourcefeatures;

import com.easybacklog.client.EasyBacklogGlobalVariables;
import com.easybacklog.client.model.ProjectClass;
import com.easybacklog.client.model.ProjectFeature;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;

public class SourceFeaturesList extends FlexTable {

	public SourceFeaturesList() {

		this.setWidth("650px");

		setBorderWidth(1);

		setCellPadding(5);

		gridColumns();

		gridRows();
	}

	private void gridColumns() {

		this.setHTML(0, 0, "<B>Feature Name</B>");
		this.getColumnFormatter().setWidth(0, "400px");

		this.setHTML(0, 1, "<B>Status</B>");
		this.getColumnFormatter().setWidth(4, "160px");
	}

	private void gridRows() {

		int row = 0;
		for (ProjectClass entry : EasyBacklogGlobalVariables.sourceFeatures) {

			row++;

			this.setWidget(row, 0, getName(entry));

			this.setText(row, 1, entry.getStatus());

		}
	}

	private HTML getName(final ProjectFeature backlogEntry) {

		HTML htmlName = new HTML("<a href=#>" + backlogEntry.getFeatureName()
				+ "</a>");

		htmlName.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

			}
		});

		return htmlName;
	}
}
